/*
 * Copyright 2016 jeasonlzy(廖子尧)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.equipment.net;

import android.content.Context;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lzy.okgo.request.base.Request;
import com.android.equipment.net.callbck.JsonCallback;


public abstract class DialogCallback<T> extends JsonCallback<T> {

    BasePopupView dialog;

    private void initDialog(Context mContext) {
        dialog = new XPopup.Builder(mContext).asLoading();
    }

    public DialogCallback(Context activity) {
        super();
        initDialog(activity);
    }

    public DialogCallback(Context mContext, Class<T> clazz) {
    }

    @Override
    public void onStart(Request<T, ? extends Request> request) {
        super.onStart(request);
        if (dialog != null && !dialog.isShow()) {
            dialog.show();
        }
    }

    @Override
    public void onFinish() {
        //网络请求结束后关闭对话框
        if (dialog != null && dialog.isShow()) {
            dialog.delayDismiss(500);
        }
    }
}
